package com.ruoyi.duty.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.duty.domain.bo.DutyJdxcBo;
import com.ruoyi.duty.domain.vo.DutyJdxcVo;
import com.ruoyi.duty.service.IDutyJdxcService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 戒毒宣传
 *
 * @author xiaohao
 * @date 2023-01-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/duty/jdxc")
public class DutyJdxcController extends BaseController {

    private final IDutyJdxcService iDutyJdxcService;

    /**
     * 查询戒毒宣传列表
     */
    @SaIgnore
    @GetMapping("/list")
    public TableDataInfo<DutyJdxcVo> list(DutyJdxcBo bo, PageQuery pageQuery) {
        return iDutyJdxcService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询戒毒宣传列表
     *
     * @return
     */
    @SaIgnore
    @PostMapping("query")
    public R<List<DutyJdxcVo>> query(@RequestBody DutyJdxcBo dutyJdxcBo) {
        return R.ok(iDutyJdxcService.queryList(dutyJdxcBo));
    }

    /**
     * 导出戒毒宣传列表
     */
    @Log(title = "戒毒宣传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DutyJdxcBo bo, HttpServletResponse response) {
        List<DutyJdxcVo> list = iDutyJdxcService.queryList(bo);
        ExcelUtil.exportExcel(list, "戒毒宣传", DutyJdxcVo.class, response);
    }

    /**
     * 获取戒毒宣传详细信息
     *
     * @param jdxcId 主键
     */
    @SaIgnore
    @GetMapping("/{jdxcId}")
    public R<DutyJdxcVo> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long jdxcId) {
        return R.ok(iDutyJdxcService.queryById(jdxcId));
    }

    /**
     * 新增戒毒宣传
     */
    @SaCheckPermission("duty:jdxc:add")
    @Log(title = "戒毒宣传", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DutyJdxcBo bo) {
        return toAjax(iDutyJdxcService.insertByBo(bo));
    }

    /**
     * 修改戒毒宣传
     */
    @SaCheckPermission("duty:jdxc:edit")
    @Log(title = "戒毒宣传", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DutyJdxcBo bo) {
        return toAjax(iDutyJdxcService.updateByBo(bo));
    }

    /**
     * 删除戒毒宣传
     *
     * @param jdxcIds 主键串
     */
    @SaCheckPermission("duty:jdxc:remove")
    @Log(title = "戒毒宣传", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jdxcIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] jdxcIds) {
        return toAjax(iDutyJdxcService.deleteWithValidByIds(Arrays.asList(jdxcIds), true));
    }
}
